package chen.jia.xin.finalproject.LogView;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import chen.jia.xin.finalproject.BaseActivity;
import chen.jia.xin.finalproject.R;

import static android.widget.Toast.makeText;

public class CreateUserActivity extends BaseActivity {
    //用户注册时的信息
    private Button create_user;
    private EditText user_name;
    private EditText password;
    private EditText confirm_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_user);
        create_user = findViewById(R.id.createUser);
        user_name = findViewById(R.id.user_name_input);
        password = findViewById(R.id.user_password_input);
        confirm_password = findViewById(R.id.confirm_user_password_input);
        create_user.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(password.getText()!=null&&password.getText().toString().equals(confirm_password.getText().toString())){
                    creatingUser(user_name.getText().toString(),password.getText().toString());
                }else {
                    makeText(CreateUserActivity.this,"密码输入请一致~~",Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    public void creatingUser(String user_name,String user_password){
        //向数据库中添加数据
        User user = new User();
        user.setUserName(user_name);
        user.setUserPassword(user_password);
        user.save();
        makeText(CreateUserActivity.this,"用户注册成功~",Toast.LENGTH_LONG).show();
        finish();
    }
}
